import 'package:flutter/material.dart';
import 'package:kq_flutter_core_widget/utils/kq_screen_util.dart';
import 'package:kq_flutter_core_widget/widgets/keepalive/kq_keep_alive.dart';
import 'package:kq_flutter_widgets/widgets/tabbar/kq_tab_bar.dart';
import 'package:kq_flutter_widgets/widgets/tabbar/kq_tab_bar_page_view.dart';
import 'package:kq_flutter_widgets/widgets/titleBar/kq_title_bar.dart';

/// KqTabBar + KqTabBarView 演示
class TabBarAndViewDemoPage extends StatelessWidget {
  const TabBarAndViewDemoPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: KqHeadBar(
        headTitle: "TabBar + TabBarView演示",
      ),
      body: KqTabBarPageView(shouldIgnorePointerWhenScrolling: false, tabs: [
        TabDataEntity('一级标题1'),
        TabDataEntity('一级标题2'),
        TabDataEntity('一级标题3'),
      ], pages: [
        _buildContent('一级页面1'),
        KqKeepAlive(child: _buildLevel2()),
        KqKeepAlive(child: _buildLevel22()),
      ]),
    );
  }

  Widget _buildLevel2() {
    return KqTabBarPageView(shouldIgnorePointerWhenScrolling: false, tabs: [
      TabDataEntity('二级标题1'),
      TabDataEntity('二级标题2'),
      TabDataEntity('二级标题3')
    ], pages: [
      _buildContent('二级页面1'),
      _buildContent('二级页面2'),
      _buildContent('二级页面3')
    ]);
  }

  Widget _buildLevel22() {
    return KqTabBarPageView(shouldIgnorePointerWhenScrolling: false, tabs: [
      TabDataEntity('二级标题4'),
      TabDataEntity('二级标题5'),
      TabDataEntity('二级标题6')
    ], pages: [
      _buildContent('二级页面4'),
      KqKeepAlive(child: _buildLevel3()),
      _buildContent('二级页面6')
    ]);
  }

  Widget _buildLevel3() {
    return KqTabBarPageView(shouldIgnorePointerWhenScrolling: false, tabs: [
      TabDataEntity('三级标题1'),
      TabDataEntity('三级标题2'),
      TabDataEntity('三级标题3')
    ], pages: [
      _buildContent('三级页面1'),
      _buildContent('三级页面2'),
      _buildContent('三级页面3')
    ]);
  }

  Widget _buildContent(String content) {
    return Align(
      alignment: Alignment.center,
      child: Text(
        content,
        style: TextStyle(color: Colors.black, fontSize: 18.sp),
      ),
    );
  }
}
